--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_yagokoro_eirin = General:new(extension, "hy_yagokoro_eirin", "ten_k", 4, 4, General.Female)
    local wise_brain = fk.CreateSkill {
        name = "wise_brain",
    }
    wise_brain:addEffect(fk.CardUseFinished, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and target == player and player:getMark("wise_brain-phase") == data.card.id and data.from == player and player.phase == Player.Play
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = table.filter(room:getOtherPlayers(player), function(t)
                return #t:getCardIds("h") > 0
            end)
            event:setCostData(self, table.map(room:askToChoosePlayers(player, {
                targets = targets,
                min_num = 1,
                max_num = 1,
                prompt = "wise_brain_prompt",
                skill_name = wise_brain.name
            }), Util.IdMapper))
            return #event:getCostData(self) == 1
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local skillTarget = room:getPlayerById(event:getCostData(self)[1])
            if #skillTarget:getCardIds("h") == 0 then
                return
            end
            local result = HY.AskToDiscardSameTime(room, {
                {
                    skillTarget,
                    {
                        min_num = 1,
                        max_num = 2,
                        skill_name = wise_brain.name,
                        cancelable = false,
                        prompt = "wise_brain_prompt_discard_target:" .. player.id .. "::" .. data.card:toLogString(),
                    }
                },
                {
                    player,
                    {
                        min_num = 1,
                        max_num = 1,
                        skill_name = wise_brain.name,
                        prompt = "wise_brain_prompt_discard_self",
                    }
                }
            })
            local targetCards = result[skillTarget]
            local selfCard = result[player]
            local selfTotal = data.card.number + table.sum(selfCard, function(id)
                return Fk:getCardById(id).number
            end)
            local targetTotal = table.sum(targetCards, function(id)
                return Fk:getCardById(id).number
            end)
            local drawTarget
            if selfTotal > targetTotal then
                drawTarget = room:askToChoosePlayers(player, {
                    targets = room.alive_players,
                    min_num = 1,
                    max_num = 1,
                    prompt = "wise_brain_prompt_draw",
                    skill_name = wise_brain.name,
                    cancelable = false
                })
                drawTarget = drawTarget[1]
                room:drawCards(drawTarget, 3, wise_brain.name)
            end
            if #selfCard > 0 then
                local giveTarget = room:askToChoosePlayers(player, {
                    targets = table.filter(room.alive_players, function(t)
                        return t ~= drawTarget
                    end),
                    min_num = 1,
                    max_num = 1,
                    prompt = "wise_brain_prompt_give",
                    skill_name = wise_brain.name
                })
                if #giveTarget > 0 then
                    giveTarget = giveTarget[1]
                    room:obtainCard(giveTarget, selfCard, true, fk.ReasonPrey, player, wise_brain.name)
                end
            end
        end,
    })
    wise_brain:addEffect(fk.PreCardUse, {
        can_refresh = function(self, event, target, player, data)
            return target == player and player:getMark("wise_brain-phase") == 0 and data.from == player and player.phase == Player.Play
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            room:setPlayerMark(player, "wise_brain-phase", data.card.id)
        end
    })
    extension:loadSkillSkels { wise_brain }
    hy_yagokoro_eirin:addSkill("wise_brain")
    Fk:loadTranslationTable {
        ["hy_yagokoro_eirin"] = "八意永琳",
        ["#hy_yagokoro_eirin"] = "贤达果敢",
        ["illustrator:hy_yagokoro_eirin"] = "luan",
        ["designer:hy_yagokoro_eirin"] = "黑曜人形",
        ["cv:hy_yagokoro_eirin"] = "",

        ["wise_brain"] = "思兼",
        [":wise_brain"] = "你于出牌阶段使用第一张牌结算结束后，可以令一名其他角色弃置一至二张手牌，同时你可以弃置一张手牌：若你的弃置牌与使用牌点数之和大于其弃置牌点数之和，你令一名角色摸三张牌。然后你可以令一名未因此摸牌的角色获得你的弃置牌。",
        ["wise_brain_prompt"] = "思兼：你可以选择一名角色与你弃牌",
        ["wise_brain_prompt_discard_target"] = "思兼：%src使用了%arg，你须弃置一至二张牌",
        ["wise_brain_prompt_discard_self"] = "思兼：你可以弃置一张牌",
        ["wise_brain_prompt_draw"] = "思兼：令一名角色摸三张牌",
        ["wise_brain_prompt_give"] = "思兼：你可以令一名角色获得你的弃置牌",
    }
end
